package com.example.demo.information.repository;

import com.example.demo.information.entity.Bjxx;
import com.example.demo.information.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentRepository extends JpaRepository<Student,Long> {
    List<Student> findByNameLike(String name);

    @Query("select p from Bjxx p")
    List<Bjxx> findBjxxAll();

    List<Student> findBySfzOrXjfh(String sfz, String xjfh);

    List<Student> findBySfzOrXjfhOrNameLike(String sfz, String xjfh, String name);

    Student findBySfz(String sfz);

    @Query(nativeQuery = true,value = "select s.* from student s where s.bjxx_id=?1")
    List<Student> findByBjId(String bjId);

    @Query("select s from Student s where s.school.id=?1")
    List<Student> findByXxxxId(Long xxxxId);

    @Query(nativeQuery = true, value = " select s.* from student s where s.bjxx_id =?1")
    List<Student> findByBjxxId(Long bjxxId);

    @Query("select s from Student s where s.school.id=?1 and( sfz=?2 or xjfh=?3 or name like ?4 )")
    List<Student> findByXxxxIdAndSfzOrXjfhOrNameLike(Long xxid, String sfz, String xjfh, String name);

    @Query("select s from Student s where s.bjxx.id=?1 and( sfz=?2 or xjfh=?3 or name like ?4 )")
    List<Student> findByBjxxIdAndSfzOrXjfhOrNameLike(Long bjid, String sfz, String xjfh, String name);
}